package system_manager

import (
	"fmt"
	"gopkg/app/interfaces"
	"gopkg/app/internal/module"
)

func NewSystemManager() interfaces.SystemManager {
	sm := &systemManager{
		systemMap: make(map[string]interfaces.System),
	}
	return sm
}

type systemManager struct {
	module.ModuleLifeManager
	systemMap map[string]interfaces.System
}

func (sm *systemManager) RegisterSystem(s interfaces.System) {
	_, exist := sm.systemMap[s.Name()]
	if exist {
		panic(fmt.Sprintf("system [%v] duplicate", s.Name()))
	}
	sm.systemMap[s.Name()] = s
	sm.RegisterModule(s)
}

func (sm *systemManager) GetSystem(name string) interfaces.System {
	return sm.systemMap[name]
}
